<template>
  <div style="background-color: #FFFFFF; padding: 20px;">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

      <el-form-item label="脚本名称" prop="title">
        <el-input v-model="ruleForm.title"></el-input>
      </el-form-item>

      <el-form-item label="shell脚本" prop="shell">
        <el-input
          type="textarea"
          :autosize="{ minRows: 4, maxRows: 20}"
          placeholder="请输入内容"
          v-model="ruleForm.shell">
        </el-input>
      </el-form-item>

      <el-form-item label="编码格式" prop="encoding">
        <el-input v-model="ruleForm.encoding"></el-input>
      </el-form-item>

      <el-form-item label="操作系统" prop="os">
        <el-select v-model="ruleForm.os" placeholder="请选择系统" style="width: 100%;">
          <el-option
            v-for="(item,index) in optionsSystem"
            :key="index"
            :label="item.value"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="是否关闭进程" prop="shell_status">
        <el-switch v-model="ruleForm.shell_status">
        </el-switch>
      </el-form-item>

      <el-form-item label="是否删除文件" prop="file_status">
        <el-switch v-model="ruleForm.file_status">
        </el-switch>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm()">保存</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
  export default {
    name: 'EditMyShell',
    data() {
      return {
        EditUrl: this.$http.MyShellURL,  // get编辑的URL
        EditIdStr: 'shell_id',  // 模块id字符串
        pushObjName: 'MyShell',  // 成功后跳转的路由

        optionsSystem: [],

        ruleForm: {
          title: '',//脚本名称
          shell: '',//shell脚本
          os:'',  // 操作系统
          encoding:'',  //编码格式
          shell_status:'',  //是否关闭进程
          file_status:'',  //是否删除文件
        },  //
        rules: {
          title: [
            {required: true, message: '请输入脚本名称', trigger: 'blur'},
            {min: 1, max: 40, message: '长度在 1 到 40 个字符', trigger: 'blur'}
          ],
          shell: [
            {required: true, message: '请输入脚本', trigger: 'blur'},
          ],
          os: [
            {required: true, message: '请输入操作系统', trigger: 'blur'},
          ],
        },
      };
    },
    created() {
      this.getEditData();   // get回将要编辑的数据
      this.optionsSystem = this.getChoices.my_shell.system;
    },
    methods: {
      submitForm() {
        this.$myTool.submitForm(this)
      },

      // get回将要编辑的数据
      getEditData() {
        this.$myTool.getEditData(this)
      },

      //
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    computed: {
      getChoices() {
        return this.$store.state.choicesInfo
      }
    },
  }
</script>
